class OperatorsController < ApplicationController
  protect_from_forgery :only => [:create, :destroy, :update]

  def index
    @operators = Operator.find(:all)

    respond_to do |format|
      format.html
      format.xml  { render :xml => @operators }
    end
  end

  def show
    @operator = Operator.find(params[:id])

    respond_to do |format|
      format.html
      format.xml  { render :xml => @operator }
    end
  end

  def new
    @operator = Operator.new

    respond_to do |format|
      format.html
      format.xml  { render :xml => @operator }
    end
  end

  def edit
    @operator = Operator.find(params[:id])
  end

  def create
    @operator = Operator.new(params[:operator])

    respond_to do |format|
      if @operator.save
        flash[:notice] = 'Operatore creato con successo.'
        format.html { redirect_to(@operator) }
        format.xml  { render :xml => @operator, :status => :created, :location => @operator }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @operator.errors, :status => :unprocessable_entity }
      end
    end
  end

  def update
    @operator = Operator.find(params[:id])

    respond_to do |format|
      if @operator.update_attributes(params[:operator])
        flash[:notice] = 'Operatore aggiornato con successo.'
        format.html { redirect_to(@operator) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @operator.errors, :status => :unprocessable_entity }
      end
    end
  end

  def destroy
    @operator = Operator.find(params[:id])
    @operator.destroy

    respond_to do |format|
      format.html { redirect_to(operators_url) }
      format.xml  { head :ok }
    end
  end
end
